/*
 * Copyright (C) Michael Opitz
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
 * USA
 */
#ifndef IC_ACCEPTOR_H
#define IC_ACCEPTOR_H

#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>

#include "../handler/event_handler.h"
#include "../handler/multicaster.h"
#include "../network/connection_manager.h"

#include "ic_handler.h"

/** 
 * \brief This namespace includes all user-specific handlers for the iRoom.
 * \author Michael Opitz
 */
namespace user_handler {
	/** 
	 * This class is a acceptor for the microcontroller. It creates a new
	 * ic_handler every time a new connection from a webserver is
	 * established.
	 * \brief This class is a acceptor for the microcontroller.
	 */
	class ic_acceptor : public handler::event_handler {
	public:
		/** 
		 * \brief ic_acceptor creates a new ic_acceptor
		 * 
		 * \param ic is the socket to the microcontroller
		 * \param web_sock is the socket to the web-listener
		 * \param mul is a shared_ptr to the multicaster-object
		 * \param mgr is a shared_ptr to the connection_manager-object
		 */
		ic_acceptor(boost::shared_ptr<network::i_socket> ic,
			boost::shared_ptr<network::i_socket> web_sock,
			boost::weak_ptr<handler::multicaster> mul,
			boost::shared_ptr<network::connection_manager> mgr)
		: _ic(ic), _web(web_sock), _multi(mul), _mgr(mgr)
		{}
		virtual ~ic_acceptor() {}
		/** 
		 * \brief handle_event handles all events concerning this class.
		 * 
		 * \param n is the received message from the message_queue.
		 */
		virtual void handle_event(
			boost::shared_ptr<network::message> n);
	private:
		boost::shared_ptr<network::i_socket> _ic;
		boost::shared_ptr<network::i_socket> _web;
		boost::weak_ptr<handler::multicaster> _multi;
		boost::shared_ptr<network::connection_manager> _mgr;
	};
}

#endif

